

CXX	:= g++
LD	:= g++
AR	:= ar
CXXFLAGS := -Wall -O2 -Werror -g
INCLUDES = -I../common -I../log

TARGET	= a.out
SERVER  = s.out

LINKS	= -L.
LIBS	= -ldl

#SOURCES := main.cc

SOURCES :=
SOURCES += ../common/tools/dump.cc
SOURCES += ../common/tools/socket.cc
SOURCES += ../common/tools/select.cc
SOURCES += ../common/tools/file_util.cc
SOURCES += ../common/tools/string_util.cc

SOURCES += ../log/log_dispatcher.cc
SOURCES += ../log/logging.cc
SOURCES += ../log/logtracer_shell.cc
# SOURCES += ../log/logtracer_udp.cc
SOURCES += ../log/log_util.cc



OBJS := $(SOURCES:.cc=.o)
DEPS := $(SOURCES:.cc=.d)

all: prebuild $(TARGET) $(SERVER)

$(TARGET): $(OBJS) main.o
	@echo Linking $@ ...
	$(LD) main.o $(OBJS) $(LINKS) $(LIBS) -o$@
	@echo -------------------------------------------
	@echo done.

$(SERVER): $(OBJS) ser.o
	@echo Linking $@ ...
	$(LD) ser.o $(OBJS) $(LINKS) $(LIBS) -o$@
	@echo -------------------------------------------
	@echo done.


.cpp.o:
	@echo Compling $@ ...
	$(CXX) -c $< $(INCLUDES) $(CXXFLAGS)  -o $@
	@echo -------------------------------------------

.cc.o:
	@echo Compling $@ ...
	$(CXX) -c $< $(INCLUDES) $(CXXFLAGS)  -o $@
	@echo ------------------------------------------

%.d:%.cc
	$(CXX) -MM $< $(INCLUDES) $(CXXFLAGS) -o $@

prebuild:
	#echo -------

include $(DEPS)

clean:
	rm -fr $(OBJS) $(DEPS)



